package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements update flower in the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageUpdateFlower {

	private ConnectionToClient client ;
	private String[] str; 
	static int row1;
/**
 * Constructor of this class 	
 * @param str
 * @param client
 */
	public MessageUpdateFlower(String[] str, ConnectionToClient client){
		
		this.client= client ;
		this.str= str; 	
	
	}
/**
 * This method update flower details 	
 * @throws SQLException
 * @throws IOException
 */
	public void UpdateFlower() throws SQLException, IOException{
		
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement sid = sc.getConnection().prepareStatement("SELECT * FROM db.flowers where name='"+str[1]+"'and color='"+str[2]+"';" );
		ResultSet rss= sid.executeQuery();
		if(rss.next())
		{
		 ArrayList<Object> uf=new ArrayList<Object>();
		 uf.add("UpdateFlower");
		 uf.add(rss.getString(1));
		 uf.add(rss.getString(2));
		 uf.add(rss.getInt(3));
		 uf.add(rss.getInt(4));
		 uf.add(rss.getInt(5));
		 uf.add(rss.getInt(6));
	
		 client.sendToClient(uf);
		}


}
}
